package com.rentcars.controller;

import com.github.pagehelper.PageInfo;
import com.rentcars.entity.Baclist;
import com.rentcars.service.BacListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 任梦强
 * @data 2021.3.3
 */
@RestController
public class BacListController {

    @Autowired
    private BacListService bacListService;

    @RequestMapping("/baclist")
    public PageInfo<Baclist> selectBacList(Baclist baclist,Integer curr,Integer pageSize){
        PageInfo<Baclist>baclistPageInfo=bacListService.selectBacList(baclist,curr,pageSize);
       /* Map<String,Object>map=new HashMap<>();
        map.put("bacListInfo",baclist);*/
        return baclistPageInfo;
    }
    @RequestMapping("/baclist-list")
    public ModelAndView toBacList(){
        return new ModelAndView("baclist-list");
    }

    @RequestMapping("/bacListAdd")
    public int insertSelective(Baclist baclist){
        return bacListService.insertSelective(baclist);
    }

    @RequestMapping("/baclist-add")
    public ModelAndView toAdd(){
        return new ModelAndView("baclist-add");
    }


    @RequestMapping("/bacListPage")
    public ModelAndView findUser(String bid){
        Baclist baclist=bacListService.selectById(bid);
        Map<String,Object>map=new HashMap<>();
        map.put("list",baclist);
        return new ModelAndView("baclist-edit",map);
    }

    @RequestMapping("/bacListEdit")
    public int updateByPrimaryKey(Baclist baclist){
        return bacListService.updateByPrimaryKey(baclist);
    }

    @RequestMapping("/bacListDel")
    public int deleteByPrimaryKey(String bid){
        return bacListService.deleteByPrimaryKey(bid);
    }

    @RequestMapping("/bacListDelete")
    public int deleteBacList(@RequestParam String bacListUid){
        List<String> bidList= Arrays.asList(bacListUid.split(","));
        return bacListService.deleteBacList(bidList);

    }

    public BacListService getBacListService() {
        return bacListService;
    }

    public void setBacListService(BacListService bacListService) {
        this.bacListService = bacListService;
    }
}
